<template>
  <!-- 标签跳转 -->
  <!-- <div class="goods-list">
    <router-link :to="'/home/goodsinfo/'+item.id" tag="div" class="goods-item" v-for="item in goodslist" :key="item.id">
      <img :src="item.img">
      <h1 class="title">{{ item.title }}</h1>
      <div class="info">
        <p class="price">
          <span class="now">{{ item.now }}</span>
          <span class="old">{{ item.old }}</span>
        </p>
        <p class="cell">
          <span>热卖中</span>
          <span>剩余{{ item.count }}件</span>
        </p>
      </div>
    </router-link>
    <mt-button type="danger" size="large" @click="getGoodsList">加载更多</mt-button>
  </div> -->


  <!-- 编程式导航 -->
  <div class="goods-list">
    <div class="goods-item" v-for="item in goodslist" :key="item.id" @click="GoToInfo(item.id)">
      <img :src="item.img">
      <h1 class="title">{{ item.title }}</h1>
      <div class="info">
        <p class="price">
          <span class="now">￥{{ item.now }}</span>
          <span class="old">￥{{ item.old }}</span>
        </p>
        <p class="cell">
          <span>热卖中</span>
          <span>剩余{{ item.count }}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getGoodsList">加载更多</mt-button>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      goodslist: [],
      pageindex: 0,
      pagesize: 6
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.$http
        .get("goods?_start=" + this.pageindex + "&_limit=" + this.pagesize)
        .then(
          result => {
            this.goodslist = this.goodslist.concat(result.body);
            this.pageindex += this.pagesize;
          },
          error => {
            Toast("数据获取失败！");
          }
        );
    },
    GoToInfo(id) {
      console.log(this)
      this.$router.push('/home/goodsinfo/'+id)
    }
  }
};
</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  padding: 8px;
  justify-content: space-between;
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    min-height: 301px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 14px;
          margin-left: 10px;
        }
      }
      .cell {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
      }
    }
  }
}
</style>
